﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Controls_TYLX_SHANGPINControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void Bind(string productid)
    {
        DropDownList1.Items.Clear();
        DropDownList1.Items.Add(new ListItem("请选择类型", "0"));
        DropDownList1.AppendDataBoundItems = true;
        DropDownList1.DataSource = new BLL.TYLX().GetAllList();
        DropDownList1.DataTextField = "TYPENAME";
        DropDownList1.DataValueField = "LXID";
        DropDownList1.DataBind();
        Hidden1.Value = productid;
        Model.TYLX_SHANGPIN ty_sp = new Model.TYLX_SHANGPIN();
        ty_sp = new BLL.TYLX_SHANGPIN().GetModel(productid);
        if (ty_sp != null)
        {
            DropDownList1.SelectedValue = ty_sp.LXID.ToString();
        }
    }
    public void Add()
    {
        if (Hidden1.Value.Length < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请选择商品');", true);
            return;
        }
        string productid = Hidden1.Value;
        if (DropDownList1.SelectedIndex < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请选择类型');", true);
            return;
        }
        else
        {
            Model.TYLX_SHANGPIN ty_sp = new Model.TYLX_SHANGPIN();
            ty_sp.LXID = int.Parse(DropDownList1.SelectedValue);
            ty_sp.SPDM = productid;
            int re = new BLL.TYLX_SHANGPIN().Add(ty_sp);
            if (re < 1)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('提交失败';)", true);
            }
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        Add();
    }
}
